/*import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if (a > 1000 || a < -1000){
                System.out.println("|a|>1000");
            }else{
                System.out.println(a+b);
            }
        }
    }
}*/


/*
import java.util.Scanner;

class Ring{
    private int innerRadius;
    private int outerRadius;

    public Ring(int innerRadius, int outerRadius) {
        this.innerRadius = innerRadius;
        this.outerRadius = outerRadius;
    }

    public int getInnerRadius() {
        return innerRadius;
    }

    public void setInnerRadius(int innerRadius) {
        this.innerRadius = innerRadius;
    }

    public int getOuterRadius() {
        return outerRadius;
    }

    public void setOuterRadius(int outerRadius) {
        this.outerRadius = outerRadius;
    }

    public Ring() {
        this(1,3);
    }

    public int getArea(){
        double area = (Math.PI * outerRadius * outerRadius)
                - (Math.PI * innerRadius * innerRadius);
        return (int)area;
    }
}


public class  Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int innerRadius = scanner.nextInt();
        int outerRadius = scanner.nextInt();
        Ring ring = new Ring(innerRadius,outerRadius);
        System.out.println("constructor");
        System.out.println(ring.getArea());

        Ring ring1 = new Ring();
        System.out.println("constructor");
        System.out.println(ring1.getArea());
    }
}*/


/*
import java.util.Scanner;

class BankAccount{
    private int balance;


    public BankAccount() {
        ;
    }

    public BankAccount(int balance) {
        this.balance = balance;
    }

    public int getBalance() {
        return balance;
    }

    public int withdraw(int account){
        balance -= account;
        return balance;
    }

    public int deposit(int amount){
        balance += amount;
        return balance;
    }
}


public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int balance = scanner.nextInt();
        BankAccount bankAccount = new BankAccount(balance);
        System.out.println(bankAccount.getBalance());


        int withdraw = scanner.nextInt();
        System.out.println(bankAccount.withdraw(withdraw));

        int depositMoney = scanner.nextInt();
        System.out.println(bankAccount.deposit(depositMoney));
    }
}*/



/*
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] grade = new int[5];
        for(int i=0; i<grade.length; i++){
            grade[i] = in.nextInt();
        }

        RR rr = new RT(grade);
        double dd = rr.mark();
        System.out.printf("%.2f",dd);
    }
}
abstract class RR{
    int[] grade;
    public RR(int[] grade){
        this.grade = grade;
    }
    public abstract double mark();
}

class RT extends RR{
    @Override
    public double mark() {
        Arrays.sort(super.grade);
        double sum = 0;
        for (int i = 1; i < 4; i++) {
            sum += super.grade[i];
        }

        return sum / 3;
    }

    public RT(int[] grade) {
        super(grade);
    }
}*/


/*
class IllegalTriangleException extends RuntimeException{
    public IllegalTriangleException(String message) {
        super(message);
    }

*/
/*    public void getMessage{
        Triangle triangle = new Triangle();
        System.out.format("INvalid:%.1f,%.1f,%.1f",side1,side2,side3);
    }*//*

}

class Triangle{
    public double side1;
    public double side2;
    public double side3;


    public Triangle(double side1, double side2, double side3) throws IllegalTriangleException{
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;

        if (side1 + side2 <= side3 || side1 + side3 <= side2
              || side2 + side3 <= side1){
            throw new IllegalTriangleException("非法的边长");
        }
    }

    @Override
    public String toString() {
        return "Triangle [" +
                "side1=" + side1 +
                ", side2=" + side2 +
                ", side3=" + side3 +
                ']';
    }
}*/


/*import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Person{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person(){   //无参的注意一下

    }


    @Override
    public String toString() {
        return "Person [" +
                "name='" + name + '\'' +
                ", age=" + age +
                ']';
    }
}


public class Main {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();

        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        for (int i = 0; i < num; i++) {
            String name = scanner.next();
            int age = scanner.nextInt();
            Person person = new Person(name, age);
            personList.add(person);
        }

        boolean flag = true;
        String searchName = scanner.next();
        for (int i = 0; i < num; i++) {
            System.out.println(personList.get(i));
            if (personList.get(i).getName().equals(searchName)){
                System.out.println("查询结果：");
                System.out.println(personList.get(i));
                flag = false;
            }
        }

        if (flag){
            System.out.println("not found");
        }

    }
}*/



import javax.swing.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
/*import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str =sc.nextLine();
        String[] s = str.split(" ");
        TreeSet<String> s1 = new TreeSet<String>();
        TreeSet<String> s2 = new TreeSet<String>();
        int i = 0;



        while(s1.size() < 5 && i < s.length){
            s1.add(s[i++]);
        }
        while(s2.size() < 5 && i < s.length){
            s2.add(s[i++]);
        }


        TreeSet<String> s3 = new TreeSet<String>();
        s3.addAll(s1);
        s3.addAll(s2);
        //输出
        Iterator it = s3.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
    }
}*/



/*
class Line{
    public Point p1;
    public Point p2;

    public Line(Point p1, Point p2) {
        this.p1 = p1;
        this.p2 = p2;
    }


    public Point getP1() {
        return p1;
    }

    public void setP1(Point p1) {
        this.p1 = p1;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point p2) {
        this.p2 = p2;
    }

    public int getLength(){    //不确定
        return -1;
    }

    @Override
    public String toString() {
        return "Line [" +
                "p1=" + p1.toString() +
                ", p2=" + p2.toString() +
                ']';
    }
}

class Point{
    private int x, y;// x,y为点的坐标
    //求两点之间的距离
    public double distance(Point p1) {
        return Math.sqrt((p1.x -this.x)*(p1.x -this.x)+(p1.y-this.y)*(p1.y-this.y));
    }
    public Point(int x, int y) {
        super();
        this.x = x;
        this.y = y;
    }
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }
    public Point() {
        super();
        x = y =0;
    }
    @Override
    public String toString() {
        return "Point [x=" + x + ", y=" + y + "]";
    }
}


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int linesLen = scanner.nextInt();
        Line[] lines = new Line[linesLen];

        for (int i = 0; i < linesLen; i++) {
            int point1X = scanner.nextInt();
            int point1Y = scanner.nextInt();
            int point2X = scanner.nextInt();
            int point2Y = scanner.nextInt();
            Point point1 = new Point(point1X,point1Y);
            Point point2 = new Point(point2X,point2Y);

            Line line = new Line(point1, point2);
            lines[i] = line;
        }

        //循环输出
        for (int i = 0; i < linesLen; i++) {
            System.out.println(lines[i]);
            System.out.println("此线段的长度为：" + lines[i].p1.distance(lines[i].p2));
        }
    }
}*/


/*
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] ch = str.split(" ");

        int count = 0;
        for (int i = 1; i < ch.length; i++) {
            if (ch[i].charAt(0) == ch[0].charAt(0)){
                count++;
            }
        }

        System.out.println(count);
    }
}*/


class PersonSortable2{
    public String name;
    public int age;

    public PersonSortable2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return this.name + "-" + this.age;
    }
}

class NameCompactor implements Comparator<String>{
    @Override
    public int compare(String o1, String o2) {
        return o1.compareTo(o2);
    }
}

class AgeCompactor implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o1 - o2;
    }
}


public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        PersonSortable2[] persons = new PersonSortable2[n];

        for (int i = 0; i < n; i++) {
            String name = scanner.next();
            int age = scanner.nextInt();
            PersonSortable2 person = new PersonSortable2(name, age);
            persons[i] = person;
        }


        // 按照名字升序
        System.out.println("NameComparator:sort");
        for (int i = 0; i < persons.length - 1; i++) {
            for (int j = i + 1; j < persons.length; j++) {
                NameCompactor nameCompactor = new NameCompactor();
                if (nameCompactor.compare(persons[i].name,persons[j].name) > 0){
                    PersonSortable2 tmp = persons[i];
                    persons[i] = persons[j];
                    persons[j] = tmp;
                }
            }
        }

        for (int i = 0; i < persons.length; i++) {
            System.out.println(persons[i]);
        }

        //按照年龄排，排你妈逼啊
        System.out.println("AgeComparator:sort");
        for (int i = 0; i < persons.length - 1; i++) {
            for (int j = i + 1; j < persons.length; j++) {
                AgeCompactor ageCompactor = new AgeCompactor();
                if (ageCompactor.compare(persons[i].age,persons[j].age) > 0){
                    PersonSortable2 tmp = persons[i];
                    persons[i] = persons[j];
                    persons[j] = tmp;
                }
            }
        }

        for (int i = 0; i < persons.length; i++) {
            System.out.println(persons[i]);
        }
    }
}